package com.src.gui;

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import run.dbConnection;

public class AddEvent extends JFrame {

	private Mainframe parent;
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	
	private JButton eventAdd;
	private JButton eventCan;
	
	public dbConnection dbconn;
	
	private EventView eventview;
	
	/**
	 * This is the default constructor
	 */
	public AddEvent(Mainframe pat) {
		super();
                this.parent = pat;
		initialize();
		dbconn = new dbConnection();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		//fillTimeSlot();
		this.setSize(300, 400);
		this.setContentPane(getJContentPane());
		this.setTitle("Add Event");
		this.setLocationRelativeTo(null);

	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			//jContentPane.setLayout(new GridLayout(10,2,10,10));
			jContentPane.setLayout(new BorderLayout());
			
			eventview = new EventView();
			
			jContentPane.add(eventview,BorderLayout.CENTER);
			
			JPanel buttonPane = new JPanel(new FlowLayout());
			
			eventAdd = new JButton("Add Event");
			eventAdd.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if(dbconn.saveEvent(eventview.getEventSummary(), eventview.getEventCategory(), eventview.getEventStartDate(),eventview.getEventStartTime(), eventview.getEventEndDate(),eventview.getEventEndTime(), 
							eventview.getEventLocation(),eventview.getEventDesc(), eventview.getEventClass()))
					{
						JOptionPane.showMessageDialog(null,"Event Add Successful!","Confirmation",JOptionPane.PLAIN_MESSAGE);
						dispose();
                                                parent.refresh();
					}
					
				}
			});
			buttonPane.add(eventAdd);
			
			eventCan  = new JButton("Cancel");
			eventCan.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
			buttonPane.add(eventCan);
			buttonPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
			jContentPane.add(buttonPane,BorderLayout.SOUTH);
			
		}
		return jContentPane;
	}

	
	public void setEventStartDate(String date)
	{
		eventview.setEventStartDate(date);
	}
	
	public void setEventEndDate(String date)
	{
		eventview.setEventEndDate(date);
	}

}
